import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        hasLogin: false,
        nickName: '',
        avatarUrl: '',
		phone: '',
		token: '',
		code: '',
		parentId: ''
	},
    mutations: {
		wxLogin(state, v) {
			state.code = v
		},
		changePhone(state, v) {
			state.phone = v
		},
		setAvatarUrl(state, v) {
			state.avatarUrl = v
		},
		setNickName(state, v) {
			state.nickName = v
		},
        login(state, userInfo) {
			const { name: nickName, headimgurl: avatarUrl, phone, token, id } = userInfo
			state.hasLogin = true
            state.nickName = nickName || ''
            state.avatarUrl = avatarUrl || ''
			state.phone = phone || ''
            state.token = token || ''
			state.parentId = id || ''
        },
        logout(state) {
			state.hasLogin = false
            state.nickName = ''
            state.avatarUrl = ''
			state.phone = ''
            state.token = ''
			state.parentId = ''
        }
	},
    actions: {}
})

export default store